package cn.dg.manager.warehouse.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.dg.manager.common.dao.impl.BaseDaoImpl;
import cn.dg.manager.common.entity.PageEntity;
import cn.dg.manager.order.entity.OrderInfoResultBean;
import cn.dg.manager.warehouse.dao.WarehouseInfoDao;
import cn.dg.manager.warehouse.entity.WarehouseEditPageBean;
import cn.dg.manager.warehouse.entity.WarehouseInfoResultBean;
import cn.dg.manager.warehouse.entity.WarehouseInfoVO;

@Repository("warehouseInfoDao")
public class WarehouseInfoDaoImpl extends BaseDaoImpl implements WarehouseInfoDao {
	
	public static final String WAREHOUSE_INFO_SQL_PACKAGE = WarehouseInfoDao.class.getName().concat(".");

	/**
	 * 入库列表信息检索
	 */
	public PageEntity<WarehouseInfoResultBean> findWarehouseListPage(Map<String, Object> params) {
		PageEntity<WarehouseInfoResultBean> page = new PageEntity<WarehouseInfoResultBean>();
		int pg = params.get("page") != null ? Integer.parseInt(String.valueOf(params.get("page"))) : START_PAGE_INDEX;
		page.setPageNo(pg);
		page.setParams(params);
		int i = params.get("rows") != null ? Integer.parseInt(String.valueOf(params.get("rows"))) : END_PAGE_INDEX;
		page.setPageSize(i);
		page.setParams(params);
		List<WarehouseInfoResultBean> goodsTypeList = this.sqlSessionTemplate.selectList(WAREHOUSE_INFO_SQL_PACKAGE.concat("findWarehouseListPage"), page);
		page.setResults(goodsTypeList);
		return page;
	}

	/**
	 * 根据入库ID获取入库基本信息
	 */
	public WarehouseEditPageBean getWarehouseInfo(String warehouseId) {
		Map<String, Object> cond = new HashMap<String, Object>();
		cond.put("warehouseId", warehouseId);
		return this.sqlSessionTemplate.selectOne(WAREHOUSE_INFO_SQL_PACKAGE.concat("getWarehouseInfo"), cond);
	}

	/**
	 * 根据IDlist 删除入库信息
	 */
	public long deleteWarehouseInfoByIds(List<String> warehouseIDList) {
		return (long) this.sqlSessionTemplate.delete(WAREHOUSE_INFO_SQL_PACKAGE.concat("deleteWarehouseInfoByIds"), warehouseIDList);
	}

	/**
	 * 新增入库信息
	 */
	public long insertWarehouseInfo(WarehouseInfoVO warehouseInfoVO) {
		return (long) this.sqlSessionTemplate.insert(WAREHOUSE_INFO_SQL_PACKAGE.concat("insertWarehouseInfo"), warehouseInfoVO);
	}

	/**
	 * 更新入库信息
	 */
	public long updateWarehouseInfo(WarehouseInfoVO warehouseInfoVO) {
		return (long) this.sqlSessionTemplate.insert(WAREHOUSE_INFO_SQL_PACKAGE.concat("updateWarehouseInfo"), warehouseInfoVO);
	}

}
